package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;


    /**
     * 查询今日佳人
     *
     * @return 返回每日佳人数据
     */
    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest> todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询推荐用户
     *
     * @param dto 封装查询数据
     * @return 返回分页查询的用户详细数据
     */
    @GetMapping("/recommendation")
    public ResponseEntity<PageResult> recommendation(RecommendUserDto dto) {
        PageResult result = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询两人之间的推荐数据
     * 佳人信息
     *
     * @param userId 佳人id
     * @return 推荐数据
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity<TodayBest> personalInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查看陌生人问题
     *
     * @param userId 陌生人id
     * @return 返回questions
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity<String> strangerQuestions(Long userId) {
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 回复陌生人问题
     *
     * @param map userID 陌生人id reply 回复
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity<String> strangerQuestions(@RequestBody Map map) {
        String userId = map.get("userId").toString();
        Long id = Long.valueOf(userId);
        String reply = (String) map.get("reply");
        tanhuaService.replyQuestions(id, reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 展示今日佳人信息，排除喜欢和不喜欢
     *
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity cards() {
        List<TodayBest> todayBests = tanhuaService.cards();
        return ResponseEntity.ok(todayBests);
    }

    /**
     * 不喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String id) {
        tanhuaService.unlove(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 喜欢
     * @param id
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String id) {
        tanhuaService.lave(id);
        return ResponseEntity.ok(null);
    }
    /**
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,
                                                          @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list =tanhuaService.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }
}
